home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
glass
/
glass.lha
/
GLASS
/
dtm
/
test.gl
< prev
next >
Wrap
Text File
|
1991-06-18
|
1KB
|
61 lines
Basetype E;
Atom
not :- E => E,
nand2 :- E & E => E,
adc :- E & E & E => E & E,
div2 :- E => E;
Def
sel :- E & E & E => E;
sel [s, a, b] = nand2 [nand2 [not s, a], nand2 [s, b]];
Mac
divchain :- Int -> E => E -> E => E;
divchain 0 A in = in;
divchain n A in = divchain (n-1) A (A in);
Def
div1024 :- E => E;
div1024 in = divchain 10 div2 in;
Mac
adder :- Int -: n -> E^n & E^n & E => E & E^n;
adder 0 [[],[],c] = [c,[]];
adder n [a:as, b:bs, c] = [cout, s:ss]
where
[v,s] = adc [a,b,c];
[cout,ss] = adder (n-1) [as, bs, v];
endwhere;
Def
adder4 :- E^4 & E^4 & E => E & E^4;
adder4 [as,bs,c] = adder 4 [as,bs,c];
Atom
blb :- E & E => E & E;
Mac
blbrow :- Int -: n -> E^n & E => E & E^n;
blbrow 0 [[], e] = [e, []];
blbrow n [ne:ns, e] = [w, s:ss]
where
[v,s] = blb [ne,e];
[w,ss] = blbrow (n-1) [ns, v];
endwhere;
Mac
blbarray :- Int -: m -> Int -: n -> E^n & E^m => E^m & E^n;
blbarray 0 n [ns,[]] = [[],ns];
blbarray m n [ns, e:es] = [w:ws,ss]
where
[w, ins] = blbrow n [ns, e];
[ws,ss] = blbarray (m-1) n [ins,es];
endwhere;
Def
blbtest :- E^4 & E^4 => E^4 & E^4;
blbtest [ns,es] = blbarray 4 4 [ns,es];